package com.guoxin.designpattern.chapter3;

/**
 * @author guoxin
 * @date 2019/9/3
 */
public class VolatileTest2 {
    private static int initValue = 0;
    private static final int MAX_LIMIT = 50;

    public static void main(String[] args) {
        new Thread(() -> {
            while (initValue < MAX_LIMIT) {
                System.out.println("T1->" + (++initValue));
                try {
                    Thread.sleep(1);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }, "ADDER-1").start();

        new Thread(() -> {
            while (initValue < MAX_LIMIT) {
                System.out.println("T2->" + (++initValue));
                try {
                    Thread.sleep(1);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }, "ADDER-2").start();
    }
}
